/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicio.practica10;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 *
 * @author manolo
 */
public class usaFiloApiAN {

    private static final int numeroFilosofos = 5;

    public static void main(String args[]) throws InterruptedException {
        filoApiAN[] filosofos = null;

        ReentrantLock[] tenedores = new ReentrantLock[numeroFilosofos];

        for (int i = 0; i < numeroFilosofos; i++) {
            tenedores[i] = new ReentrantLock();
        }

        // Create the philosophers and start each running in its own thread.
        filosofos = new filoApiAN[numeroFilosofos];

        for (int i = 0; i < numeroFilosofos; i++) {
            filosofos[i] = new filoApiAN(tenedores[i], tenedores[(i + 1) % numeroFilosofos], i);
            new Thread(filosofos[i]).start();
        }

    }
}
